package com.gp.controller;

import com.github.pagehelper.PageInfo;
import com.gp.entity.User;
import com.gp.service.UserService;
import com.gp.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 来一杯凉咖
 * @create 2022/3/9 10:24
 */
@RestController
@RequestMapping("/system")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/findAllUser")
    public PageInfo<User> findAllUser(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "10")Integer size){
        PageInfo<User> page1 = userService.getAllUserForPage(page, size);
        return page1;
    }
    @PostMapping("/editUser")
    public CommonResult editUser(@RequestBody User user){
        return userService.editUser(user);
    }
    @GetMapping("/delUser")
    public CommonResult delUser(Integer uid){
        return userService.deleteUserById(uid);
    }

    @GetMapping("/selectUser")
    public PageInfo<User> selectUser(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "10")Integer size,String uname,String lname,String email,String phone){
        PageInfo<User> userPageInfo = userService.queryUser(page, size, uname,lname,email,phone);
        return  userPageInfo;
    }
}
